home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7148 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.3 KB  |  48 lines

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: a question (timing routine)
  5. Date: Sat, 17 Feb 96 22:44:01 GMT
  6. Organization: none
  7. Message-ID: <824597041snz@genesis.demon.co.uk>
  8. References: <4fvse1$656@pollux.usc.edu>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <4fvse1$656@pollux.usc.edu> separk@pollux.usc.edu "S. Park" writes:
  15.  
  16. >Hello,
  17. >
  18. >I would like to measure time taken for two different implementations
  19. >of merge sort.  I know I can use command "time", but I wonder if
  20. >anyone can give me some simple example code that uses "time" function
  21. >in C program so that I can modify it in my comparison.  
  22.  
  23. clock() is the normal function to use for this e.g.
  24.  
  25. #include <stdio.h>
  26. #include <time.h>
  27.  
  28. ...
  29.  
  30. {
  31.     clock_t start, end;
  32. ...
  33.     start = clock();
  34.  
  35.     /* Put code to be timed here */
  36.  
  37.     end = clock();
  38.  
  39.     printf("Time taken is %f seconds\n", (end-start) / (double)CLOCKS_PER_SEC);
  40. ...
  41. }
  42.  
  43. -- 
  44. -----------------------------------------
  45. Lawrence Kirby | fred@genesis.demon.co.uk
  46. Wilts, England | 70734.126@compuserve.com
  47. -----------------------------------------
  48.